//
//  ViewController.swift
//  UICreate
//
//  Created by fanxiaoxin_1987@126.com on 10/27/2021.
//  Copyright (c) 2021 fanxiaoxin_1987@126.com. All rights reserved.
//

import UIKit
import UICreate

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let view = UIView(.bg(.blue), .alpha(1))
        
        let b = 3 < 4
        view.build {
            let label = UILabel(.text("Title1"), .color(.red))
            if b {
                label.layout(.top(30), .centerX)
            }else{
                label.layout(.top(10), .centerX)
                UILabel(.text("Title2")).layout(.topToBottom(20), .centerX)
            }
            UIView(.bg(.yellow)) {
                UILabel(.text("VT 1")).layout(.top, .edgesX)
                UILabel(.text("VT 2")).layout(.topToBottom, .centerX)
                    .layout(for: .superview, .bottom)
            }.layout(.topToBottom(10), .centerX)
            UIButton(.text("Button1"), .color(.blue), .bg(.white), .event(self, #selector(self.clickButton)))
                .layout(.topToBottom(50), .centerX(20))
            UILabel(.text("Title3"), .color(.green), .boldFont(size: 24), .tap(self, #selector(self.clickLabel)))
                .layout(.topToBottom, .left(-20))
            UIButton(.text("Button2")).layout(.topToBottom(30), .left, .right)
            [UILabel(.text("A")), UILabel(.text("B")), UILabel(.text("C")), UILabel(.text("D"))]
                .set(.color(.red), .bg(.yellow), .center)
                .layout(first: .topToBottom, .for(.superview, .separator(.right(8), leading: 8, .bg(.systemPink))),
                        between: .separator(.rightToLeft(10), inset: .init(top: 1, left: 2, bottom: 3, right: 4), .bg(.systemGreen), .corner(2)), .width, .edgesY,
                        last: .for(.superview, .separator(.left(10), inset: .init(top: 1, left: 2, bottom: 3, right: 4), .bg(.systemPink))),
                        all: .height(100))
            UILabel(.text("F")).layout(.topToBottom(10), .centerX)
                .layout(for: .superview, .bottom)
        }

        self.view.build {
            view.layout(.centerY, .edgesX)
            UIView(.bg(.green)).layout(.topToBottom)
                .layout(for: .superview, .safeBottom, .edgesX)
        }
        
        self.view.add(UIView(.bg(.red)), layout: .safeEdgesY, .width(10))
            .makeLayout(.width(30).update)
            .remakeLayout(.safeEdgesX, .make(.equals.top.to.safe.top))
            .makeLayout(.height(30))
            .updateLayout(.height(50))
            .makeLayout(.height(40).update)
        
        view.add(UIView(.bg(.red)), layout: .left, .top, .right, .height(100))
    }
    @objc func clickButton() {
        print("Click Button")
    }
    @objc func clickLabel() {
        print("Click Label")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
